﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAO.WaiGaoQiao;
using System.Data;

namespace Model.WaiGaoQiao
{
    public class Work_Person_Unit_PostInfo
    {
        Work_ArticleBringInfo bring = new Work_ArticleBringInfo();
        #region -------------  字段------------------------
        /// <summary>
        /// ID
        /// </summary>
        public int ID { get; set; }
        /// <summary>
        /// no
        /// </summary>
        public String PersonNo { get; set; }
        /// <summary>
        /// name
        /// </summary>
        public String PersonName { get; set; }
        /// <summary>
        /// 工作服
        /// </summary>
        public int ArticleId{ get; set; }
        /// <summary>
        /// 工作服规格
        /// </summary>
        public int RuleId { get; set; }
        
        #endregion
        DataAccessWork_Person_Unit_Post DAS;
        /// <summary>
        /// 行记录
        /// </summary>
        private int rowcount = 0;
        public int _rowcount
        {
            get { return rowcount; }
        }
        /// <summary>
        /// 是否获得行记录
        /// </summary>
        /// <param name="isGetCount"></param>
        public Work_Person_Unit_PostInfo(bool isGetCount)
        {
            DAS = new DataAccessWork_Person_Unit_Post();
            if (isGetCount)
            {
                rowcount = DAS.GetWork_PostCount("");
            }

        }
        //构造函数
        public Work_Person_Unit_PostInfo() { }
        /// <summary>
        /// 获取劳防用品配置与发放标准数量
        /// </summary>
        /// <returns></returns>
        public int GetWork_PostCount(string condition)
        {
            string rtn = string.Empty;
            if (!string.IsNullOrEmpty(condition))
            {

                string[] query = condition.Split(',');
                if (!string.IsNullOrEmpty(query[0]))
                {
                    rtn = " And PersonNo='" + bring.RtnPidForPersonNo(query[0]) + "'";
                }
                if (!string.IsNullOrEmpty(query[1]))
                {
                    rtn += " And PersonName='" + query[1] + "'";
                }
            }


            return DAS.GetWork_PostCount(rtn);
        }


        /// <summary>
        /// 保存劳防用品配置与发放标准
        /// </summary>
        /// <param name="idab"></param>
        /// <returns></returns>
        public int SaveWork_Post(Work_Person_Unit_PostInfo sdiDetail)
        {
            //PersonNo存储过程已经转换成pid
            object[] idpara = new object[] { sdiDetail.ID, sdiDetail.PersonNo,sdiDetail.PersonName, 
                                            sdiDetail.ArticleId, sdiDetail.RuleId};
            return DAS.SaveWork_Post(idpara);
        }

        /// <summary>
        /// 获取劳防用品配置与发放标准不分页
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        public IList<Work_Person_Unit_PostInfo> GetAllPost(string condition)
        {
            IList<Work_Person_Unit_PostInfo> Idalist = new List<Work_Person_Unit_PostInfo>();
            DataSet ds = DAS.GetAllWork_Post(condition);
            Work_Person_Unit_PostInfo ideinfo;
            foreach (DataRow item in ds.Tables[0].Rows)
            {
                ideinfo = new Work_Person_Unit_PostInfo()
                {
                    ID = Convert.ToInt32(item[0]),
                    PersonNo =bring.RtnPersonNo(item[1].ToString()),
                    PersonName = Convert.ToString(item[2]),
                    ArticleId = Convert.ToInt32(item[3]),
                    RuleId = Convert.ToInt32(item[4]),
                };
                Idalist.Add(ideinfo);
            }
            return Idalist;
        }

        /// <summary>
        /// 根据ID获取劳防用品配置与发放标准实体类
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        public Work_Person_Unit_PostInfo GetAllPost(int Id)
        {
            DataRow item = DAS.GetAllWork_Post(" And id=" + Id).Tables[0].Rows[0];
            Work_Person_Unit_PostInfo ideinfo = new Work_Person_Unit_PostInfo()
            {
                ID = Convert.ToInt32(item[0]),
                PersonNo = bring.RtnPersonNo(item[1].ToString()),
                PersonName = Convert.ToString(item[2]),
                ArticleId = Convert.ToInt32(item[3]),
                RuleId = Convert.ToInt32(item[4]),
            };
            return ideinfo;
        }
        /// <summary>
        /// 根据ID获取劳防用品配置与发放标准实体类
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        public Work_Person_Unit_PostInfo GetWork_Person_Unit_PostInfo(string conditon)
        {
            try
            {
                DataRow item = DAS.GetAllWork_Post(conditon).Tables[0].Rows[0];
                Work_Person_Unit_PostInfo ideinfo = new Work_Person_Unit_PostInfo()
                {
                    ID = Convert.ToInt32(item[0]),
                    PersonNo = bring.RtnPersonNo(item[1].ToString()),
                    PersonName = Convert.ToString(item[2]),
                    ArticleId = Convert.ToInt32(item[3]),
                    RuleId = Convert.ToInt32(item[4]),
                };
                return ideinfo;
            }
            catch
            {

                return null;
            }
        }


        /// <summary>
        /// 获取劳防用品配置与发放标准分页
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        public IList<Work_Person_Unit_PostInfo> GetAllPost(string condition, int pagesize, int startindex)
        {
            string rtn = string.Empty;
            if (!string.IsNullOrEmpty(condition))
            {

                string[] query = condition.Split(',');
                if (!string.IsNullOrEmpty(query[0]))
                {
                    rtn = " And PersonNo='" + bring.RtnPidForPersonNo(query[0]) + "'";
                }
                if (!string.IsNullOrEmpty(query[1]))
                {
                    rtn += " And PersonName='" + query[1] + "'";
                }
            }

            IList<Work_Person_Unit_PostInfo> Idalist = new List<Work_Person_Unit_PostInfo>();
            DataSet ds = DAS.GetAllWork_Post(rtn, pagesize, startindex);
            Work_Person_Unit_PostInfo ideinfo;
            foreach (DataRow item in ds.Tables[0].Rows)
            {
                ideinfo = new Work_Person_Unit_PostInfo()
                {
                    ID = Convert.ToInt32(item[0]),
                    PersonNo = bring.RtnPersonNo(item[1].ToString()),
                    PersonName = Convert.ToString(item[2]),
                    ArticleId = Convert.ToInt32(item[3]),
                    RuleId = Convert.ToInt32(item[4]),
                };
                Idalist.Add(ideinfo);
            }
            return Idalist;
        }



        /// <summary>
        /// 删除劳防用品配置与发放标准
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        public int DeletePost(int Id)
        {
            return DAS.DeleteWork_Post(Id.ToString());
        }
    }
}
